﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Web;
using Graffiti.Core;

namespace GraffitiExtras.Extensions.InstalledThemes
{
    [Chalk("installedThemes")]
    class InstalledThemes
    {
        public List<string> InstalledThemesList()
        {

            List<string> themeNameList = new List<string>();

            try
            {
                DirectoryInfo di = new DirectoryInfo(HttpContext.Current.Server.MapPath("~/files/themes/"));
                foreach (DirectoryInfo diChild in di.GetDirectories())
                {
                    if (!diChild.Name.StartsWith("_svn") && !diChild.Name.StartsWith(".svn"))
                    {
                        themeNameList.Add(diChild.Name);
                    }
                }

                return themeNameList;
            }
            catch (Exception ex)
            {
                Log.Error("Installed Themes List Extension", ex.Message + ex.StackTrace);
            }

            return null;
        }

        public bool FileExists(string themeName, string fileName)
        {
            return File.Exists(HttpContext.Current.Server.MapPath("~/files/themes/" + themeName + "/" + fileName));
        }
    }
}
